<?php 
include_once("../includes/mod_globals.inc.php");
global $TOP_CONTENT_CATEGORY_SID,$TOP_AREA_CATEGORY_SID,$VERIFY_MOTHER_IMAGE_PATH,$VERIFY_MOTHER_IMAGE_NAME ;

$puri = trim($_REQUEST['uri']);
$paction = $_REQUEST['action'];
$pverify_site_image_path = $puri.$VERIFY_MOTHER_IMAGE_NAME;
//$pverify_site_image_path = "http://gimg.baidu.com/img/gs.gif";//test

require("../includes/foxydb.php");
$foxydb = new Foxydb();
$foxydb->open();

$site = $foxydb->findSiteByUri($puri);
if($site){
    //already exists
}else if($paction == 'registersite' && $puri && $puri != ""){
	$isWebmaster = false;
    include('../includes/eac_curl.class.php');
    $http = new cURL();
    $result = $http->get($pverify_site_image_path);
    if ($http->success){
      $info = $http->getInfo();
      if($info['http_code'] == 200 && $info['url'] == $pverify_site_image_path){ //ok && prevent evil redirect 
        $isWebmaster = true;
      }
    }
    if($isWebmaster){
  		$status = $foxydb->registerSite($puri);
    }
}

$foxydb->close();

include("../includes/header.php");
?>


      <br/>
<TABLE align=left width="100%" cellpadding=0 cellspacing=0>
  <tr><td>
  <?php if($site || $status){?> 
    <center><?php echo $puri; ?>已经注册,<A href='updatecat.php?action=search&uri=<?php echo $puri; ?>'>点击这里进行修改</A></center>
  <?php }else{?> 
    <SCRIPT LANGUAGE="JavaScript">
    <!--
      function setImage(ele)
      {
        var verifyimage = document.getElementById("verifyimage");
        verifyimage.innerHTML = ele.value + "<?php echo $VERIFY_MOTHER_IMAGE_NAME; ?>";
      }
    //-->
    </SCRIPT>
    <center>
      <form action='registersite.php' method='POST' cellpadding=0 cellspacing=0>
        <input type='hidden' name='action' value='registersite'/>
        <TABLE align=left width="100%" cellpadding=0 cellspacing=0>
          <TR>
            <TD nowrap='true' align='right'>网址：</TD>
            <TD><INPUT id="uriinput" TYPE="text" NAME="uri" value='<?php echo $puri; ?>' size="64" onkeyup='setImage(this);'></TD>
            <TD></TD>
          </TR>
          <TR><TD nowrap='true' align='right'>格式：</TD><TD>http://www.yourwebsite.com</TD></TR>
          <TR>
            <TD>&nbsp;</TD>
			<TD colspan="2"><font color='red' size='-1'>
            为了验证你是网站的站长，请将验证图片<IMG src='<?php echo $VERIFY_MOTHER_IMAGE_PATH; ?>'/><?php echo $VERIFY_MOTHER_IMAGE_PATH; ?>放入网站的根目录,并确定查看到图片：<font color='blue'><div id='verifyimage'></div></font></font></TD>
          </TR>
		  <?php if($paction == 'registersite' && !$isWebmaster){?>
          <TR>
            <TD>&nbsp;</TD>
			<TD colspan="2"><font color='red' size='-1'>
            没有找到验证图片<IMG src='<?php echo $puri.$VERIFY_MOTHER_IMAGE_NAME; ?>'/><?php echo $puri.$VERIFY_MOTHER_IMAGE_NAME; ?>，不能登陆网址<?php echo $puri; ?></font></TD>
          </TR>
		  <?php }?>
          <TR>
            <TD></TD>
            <TD><INPUT TYPE="submit" name='submit' value='登陆网址'></TD>
            <TD></TD>
          </TR>
        </TABLE>
      </form>
    </center>
	<SCRIPT LANGUAGE="JavaScript">setImage(document.getElementById("uriinput"));</SCRIPT>

  <?php }?>
  
  </td></tr>
</TABLE>


<?php include("../includes/footer.php");?>